package com.itheima.test3;

import java.util.Objects;
import java.util.Random;

public class Role {
    /*
    文字版格斗游戏
        格斗游戏,每个游戏角色的姓名,血量,都不相同,在选定人物的时候(new对象的时候),这些信息就应该被确定下来。
     */
    private String name; // 角色名称
    private int blood; // 角色血量

    private String gender;// 性别

    private String face;// 长相 随机获取

    String[] boyFaces = {"风流俊雅", "气字轩昂", "相貌英俊", "五官端正", "相貌平平", "一塌涂", "面目狰狞"};// 男生长相
    String[] girlFaces = {"美奂绝伦", "沉鱼落雁", "婷婷玉立", "身材娇好", "相貌平平", "相貌简陋", "惨不忍睹"};// 女生长相

    // 攻击描述
    String[] attacks_desc = {
            "“%s使出了一招【背心钉】,转对方的身后,一掌向%s背心的灵台穴拍去。",
            "%s使出了一招【游空探爪】,飞起身形自半空中变堂为抓锁向%s。",
            "%s大喝一声,身形下伏,一招【雷坠地】,问%s双腿。",
            "%s运气于掌,一瞬间掌心变得血红,一式【掌心雷】,推向%s。",
            "%s阴手翻起阳手跟进,一招【没遮拦】,结结实实的捶的影%s。",
            "%s上步抢身,招中套招,一招【劈挂连坏】,连攻问%s。"
    };

    // 受伤描述
    String[] injureds_desc = {
            "结果%s退了半步,毫发无损",
            "结果给%s造成一处瘀伤",
            "结果一击命中,%s痛得弯下腰",
            "结果%s痛苦地闷哼了一声,显然受了点内伤",
            "结果%s摇摇晃晃,一跤摔倒在地",
            "结果%s脸色一下变得惨白,连退了好几步",
            "结果「轰」的一声,%s日中鲜血狂喷而出",
            "结果%s一声惨叫,像滩软泥般塌了下去"
    };

    public Role() {

    }

    public Role(String name, int blood, String gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(String gender) {
        // 根据性别随机获取长相
        Random random = new Random();
        if (Objects.equals(gender, "男")) {
            int index = random.nextInt(boyFaces.length);
            this.face = boyFaces[index];
        } else if (Objects.equals(gender, "女")) {
            int index = random.nextInt(girlFaces.length);
            this.face = girlFaces[index];
        } else {
            this.face = "普通";
        }


    }


    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public int getBlood() {
        return blood;
    }


    // 定义攻击方法
    public void attack(Role role) { // 传入被攻击的角色
        // 谁攻击谁？ 方法攻击参数
        Random random = new Random();

        // 攻击描述
        int index = random.nextInt(attacks_desc.length);
        System.out.printf(attacks_desc[index], this.getName(), role.getName());
        System.out.println();

        // 随机伤害值 1~20
        int hurt = random.nextInt(20) + 1;

        // 计算剩余血量
        int remainBlood = role.getBlood() - hurt;
        // 判断血量是否小于0
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        // 修改血量
        role.setBlood(remainBlood);

        // 受伤描述  injureds_desc  根据不同的血量进行描述

        if (remainBlood >= 90) {
            System.out.printf(injureds_desc[0], role.getName());
        } else if (remainBlood >= 80 && remainBlood < 90) {
            System.out.printf(injureds_desc[1], role.getName());
        } else if (remainBlood >= 70 && remainBlood < 80) {
            System.out.printf(injureds_desc[2], role.getName());
        } else if (remainBlood >= 60 && remainBlood < 70) {
            System.out.printf(injureds_desc[3], role.getName());
        } else if (remainBlood >= 50 && remainBlood < 60) {
            System.out.printf(injureds_desc[4], role.getName());
        } else if (remainBlood >= 40 && remainBlood < 50) {
            System.out.printf(injureds_desc[5], role.getName());
        } else if (remainBlood > 10 && remainBlood < 40) {
            System.out.printf(injureds_desc[6], role.getName());
        } else {
            System.out.printf(injureds_desc[7], role.getName());
        }

        System.out.println();


        // System.out.println(this.getName() + "攻击了" + role.getName() + "," + role.getName() + "受到" + hurt + "的伤害,鸠摩智剩余" + remainBlood + "的血量。");
    }

    // 展示角色信息
    public void showRoleInfo() {
        System.out.println("角色名称:" + this.getName());
        System.out.println("角色性别:" + this.getGender());
        System.out.println("角色血量:" + this.getBlood());
        System.out.println("角色长相:" + this.getFace());
    }


}
